package com.example.demo.topic;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitTopic {
	final static String message = "topic.message";
	
	final static String messages = "topic.messages";
	
	@Bean
	public Queue queueMessage() {
		return new Queue(RabbitTopic.message);
	}
	
	@Bean
	public Queue queueMessages() {
		return new Queue(RabbitTopic.messages);
	}
	
	//创建交换器Topic
	@Bean
	TopicExchange exchange() {
		return new TopicExchange("topicExchange");
	}
	//队列绑定到主题交换器
	@Bean
	Binding bindExchangeMessage(Queue queueMessage, TopicExchange exchange) {
		return BindingBuilder.bind(queueMessage).to(exchange).with(RabbitTopic.message);
	}
	
	//队列绑定到主题交换器
	@Bean
	Binding bindExchangeMessages(Queue queueMessage, TopicExchange exchange) {
		return BindingBuilder.bind(queueMessage).to(exchange).with("topic.#");//*表示一个词,#表示零个或多个词
	}
		
}
